import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_he/page/adopt/xin_he_adopt_num_select/xin_he_adopt_num_select_view.dart';
import 'package:xin_he/page/login/xin_he_login/xin_he_login_view.dart';
import 'package:xin_he/routes/xin_he_routes.dart';
import 'package:xin_he/utils/xh_styles.dart';
import 'package:xin_he/utils/xin_he_image.dart';

import '../../../utils/xin_he_user_data.dart';
import '../../login/xin_he_login_action.dart';
import 'xin_he_adopt_logic.dart';

class XinHeAdoptPage extends StatelessWidget {
  XinHeAdoptPage({Key? key}) : super(key: key);

  final logic = Get.put(XinHeAdoptLogic());
  final state = Get.find<XinHeAdoptLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
      body: Stack( children: [
        XinHeAssetImage('assets/images/adopt/bg_3.png',width: Get.width,fit: BoxFit.fitWidth,),

        XinHeAssetImage('assets/images/adopt/adopt_bg.png',width: Get.width,height: Get.height,fit: BoxFit.fill,),

        ///认养规则
        Positioned(
            top: Get.mediaQuery.padding.top+44 + 22,
            right: 25,
            child: GestureDetector(
                onTap: (){

                  ///isScrollControlled 决定是否是自定义的高度
                  // Get.bottomSheet(XinHeLoginPage(),persistent: false,isScrollControlled: true);
                  // showModalBottomSheet(context: context, isScrollControlled: true,builder: (ctx){
                  //   return XinHeLoginPage();
                  // });

                  // Navigator.push(context, MaterialPageRoute(builder: (context) => XinHeLoginPage()), transitionDuration: Duration(milliseconds: 500), transitionBuilder: (BuildContext context, Animation<double> animation, Animation<double> secAnimation, Widget child) {
                  //   return SlideTransition(position: Tween<Offset>(begin: Offset(0.0, -1.0), end: Offset.zero).animate(animation), child: child);
                  // });

                },
                child: XinHeAssetImage('assets/images/adopt/adopt_rules.png',width: 43,height: 47,fit: BoxFit.fill,))),

        ///认养记录
        Positioned(
            top: Get.mediaQuery.padding.top+44 + 22+ 47+15,
            right: 25,
            child: GestureDetector(
                onTap: (){
                  Get.toNamed(XinHeRoutes.adoptRecords);
                },
                child: const XinHeAssetImage('assets/images/adopt/adopt_record.png',width: 43,height: 47,fit: BoxFit.fill,))),

        logic.adoptCount.value>0? Positioned(
            top: Get.mediaQuery.padding.top+44+24,
            left: 26.5,
            child: Container(
              height: 33,
              width: 84,
              child: Stack(children: [
                Positioned(
                  top: 6,
                  child: Container(
                    height: 27,
                    width: 84,
                    padding: EdgeInsets.only(right: 10),
                    alignment: Alignment.centerRight,
                    decoration: BoxDecoration(color: XinHeColor('#ECFFCB',), borderRadius: BorderRadius.circular(13.5)),
                    child: Text('已认养 x${logic.adoptCount.value}',style: TextStyle(color: XinHeColor('#494C4B'),fontSize: 10),),
                  ),
                ),
                //
                Positioned(
                  left: 2,
                  child: XinHeAssetImage('assets/images/adopt/adopt_tree.png',width: 25.5,height: 33,),
                ),




              ],
              ),
            )):Container(),

        Positioned(
            bottom: 57,
            left: (Get.width-233)*0.5,
            child: GestureDetector(
                onTap: (){
                  if(xinHeUserData.appLoginState.value == false) {
                    XinHeLoginAction.modalToLoginPage();

                    return ;
                  }
                  Get.bottomSheet(XinHeAdoptNumSelectPage(count: logic.adoptCount.value,),isScrollControlled: true,isDismissible: true);
                },
                child: const XinHeAssetImage('assets/images/adopt/adopt_button.png',width: 233,height: 48,))),


      ],
      ),
    ));
  }
}
